home *** CD-ROM | disk | FTP | other *** search
- /*
- ** File: tree.h
- ** Author: Karen Foltz
- ** Created: 10 Oct 1986
- ** Purpose:
- ** The module "tree" contains the definition of the binary tree data
- ** structure used by the Constructive Solid Geometry modelling system
- ** to describe an object.
- ** A set of operations to help build these trees representing objects
- ** is also provided.
- */
- #include "boundingvol.h"
-
- /*
- ** Definition of the Primitive objects:
- **
- ** Sphere is of unit radius centered at the origin.
- ** Cube has sides of length 2 and is centered at the origin.
- ** Cone has height 1, radius 1 and the center of the base is at the origin.
- ** Cylinder has height 2, radius one and is centered at the origin.
- ** HalfSpace is defined by z<=0.
- ** Torus is centered at the origin. It's cross-section in the YZ
- ** plane is a circle of radius r centered at [0,1,0].
- ** r is a parameter taken from surface.parms.r.
- ** The torus is formed by rotating this cross-section around the Z axis.
- ** Mesh is a subdivision surface of user design.
- */
-
- typedef enum PrimitiveObjects {Sphere,Cube,Cone,Cylinder,HalfSpace,Torus,MeshP};
- typedef enum NodeTypes { Primitive, Composite };
- typedef enum OpCodes { Union, Intersect, Difference };
-
- typedef struct { /* A primitive object description */
- enum PrimitiveObjects shape;
- char *param; /* Pointer to object parameters */
- } PrimitiveShape;
-
- /* Surface and Material descriptions */
-
- /* descriptions of surfaces and texture models */
- typedef struct {
- struct token *texture; /* pointer to interpreter texture function */
- int emitter; /* =TRUE if fun returns emitting surfaces */
- int hollow; /* =TRUE if primitive is surface not solid */
- TransformType4D embedding; /* embedding from view to texture space */
- TransformType4D inv_embedding;/* inverse of embedding */
- } MaterialDescr;
-
-
- /*
- ** NOTE: Embedding matrices are originally between local coordinates
- ** and the parent nodes coordinate system. The procedure
- ** InitializeScene in module scene changes these tranforms to
- ** between local and view coordinates.
- */
-
- typedef struct ctree{ /* a node in the tree */
- enum NodeTypes kind; /* primitive or composite */
- TransformType4D embedding; /* the embedding matrix */
- TransformType4D invembedding; /* its inverse */
- BoundingVolume bound_volume; /* a bounding sphere */
- union {
- struct { /* info for a primitive node */
- PrimitiveShape shape; /* the primitive shape*/
- MaterialDescr surface; /* surface characteristics */
- double r; /* Torus radius */
- } p;
- struct { /* info for a composite node */
- enum OpCodes operation;
- struct ctree *l_solid_ptr;
- struct ctree *r_solid_ptr;
- } c;
- } var;
- } CSGtree;
-
- /*
- ** MakeCompositeNode(op,l_solid,r_solid,embed,invembed) makes a new
- ** internal node and returns a pointer to it.
- */
- extern CSGtree *MakeCompositeNode();
-
- /*
- ** MakePrimitiveNode(shape, embed, invembed, surface)
- ** Makes a new leaf node and returns a pointer to it.
- */
- extern CSGtree *MakePrimitiveNode();
-
- /*
- ** EmbedNode(node, embed, invembed)
- ** Pre-multiply the current embedding matrix of node by new additional
- ** embedding.
- */
- extern CSGtree *EmbedNode();
-
- /*
- ** DuplicateTree(tree) make a duplicate of the structure tree and
- ** return a pointer to it.
- */
- extern CSGtree *DuplicateTree();
-
- /*
- ** SetSurface(node,surface), CSGtree *node; MaterialDescr surface;
- ** set the surface description associated with node.
- */
- extern CSGtree *SetSurface();
-
- /*
- ** PrintCSGtree(ptr) recursively writes the contents of the tree to
- ** stdout.
- */
- extern void PrintCSGtree();
-
- extern void PrintOpcode();
- extern void PrintPrimitiveObject();
- extern void PrintNodeType();
- extern void PrintMaterial();
- extern void PrintBoundVolume();
-